﻿package plugin.chatflash.component
{
    import flash.display.*;
    import flash.filters.*;
    import flash.text.*;

    public class ChatBtn extends Sprite
    {
        private var mBtn:SimpleButton;
        private var mText:TextField;
        private var mUpIcon:DisplayObject;
        private var mDownIcon:DisplayObject;
        private var mOverIcon:DisplayObject;
        private var mSelectedUpIcon:DisplayObject;
        private var mSelectedDownIcon:DisplayObject;
        private var mSelectedOverIcon:DisplayObject;
        private var mData:Object;
        private var mSelected:Boolean = false;
        private var mFilter:DropShadowFilter;
        private var mColor:uint = 0;
        private var mSelectedColor:uint = 0;

        public function ChatBtn()
        {
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            this.mBtn = new SimpleButton();
            addChild(this.mBtn);
            this.mText = new TextField();
            this.mText.autoSize = TextFieldAutoSize.CENTER;
            this.mText.mouseEnabled = false;
            this.mText.x = 0;
            addChild(this.mText);
            return;
        }// end function

        public function set upIcon(param1:DisplayObject) : void
        {
            this.mUpIcon = param1;
            if (!this.mSelected)
            {
                this.mBtn.upState = param1;
                this.mBtn.hitTestState = param1;
            }
            return;
        }// end function

        public function get upIcon() : DisplayObject
        {
            return this.mUpIcon;
        }// end function

        public function set downIcon(param1:DisplayObject) : void
        {
            this.mDownIcon = param1;
            if (!this.mSelected)
            {
                this.mBtn.downState = param1;
            }
            return;
        }// end function

        public function get downIcon() : DisplayObject
        {
            return this.mDownIcon;
        }// end function

        public function set overIcon(param1:DisplayObject) : void
        {
            this.mOverIcon = param1;
            if (!this.mSelected)
            {
                this.mBtn.overState = param1;
            }
            return;
        }// end function

        public function get overIcon() : DisplayObject
        {
            return this.mOverIcon;
        }// end function

        public function set selectedUpIcon(param1:DisplayObject) : void
        {
            this.mSelectedUpIcon = param1;
            if (this.mSelected)
            {
                this.mBtn.upState = param1;
                this.mBtn.hitTestState = param1;
            }
            return;
        }// end function

        public function get selectedUpIcon() : DisplayObject
        {
            return this.mSelectedUpIcon;
        }// end function

        public function set selectedDownIcon(param1:DisplayObject) : void
        {
            this.mSelectedDownIcon = param1;
            if (this.mSelected)
            {
                this.mBtn.downState = param1;
            }
            return;
        }// end function

        public function get selectedDownIcon() : DisplayObject
        {
            return this.mSelectedDownIcon;
        }// end function

        public function set selectedOverIcon(param1:DisplayObject) : void
        {
            this.mSelectedOverIcon = param1;
            if (this.mSelected)
            {
                this.mBtn.overState = param1;
            }
            return;
        }// end function

        public function get selectedOverIcon() : DisplayObject
        {
            return this.mSelectedOverIcon;
        }// end function

        public function set selected(param1:Boolean) : void
        {
            if (param1 == this.mSelected)
            {
                return;
            }
            this.mSelected = param1;
            if (this.mSelected)
            {
                this.mBtn.upState = this.mSelectedUpIcon;
                this.mBtn.downState = this.mSelectedDownIcon;
                this.mBtn.overState = this.mSelectedOverIcon;
                this.mBtn.hitTestState = this.mSelectedUpIcon;
                this.mText.textColor = this.mSelectedColor;
            }
            else
            {
                this.mBtn.upState = this.mUpIcon;
                this.mBtn.downState = this.mDownIcon;
                this.mBtn.overState = this.mOverIcon;
                this.mBtn.hitTestState = this.mUpIcon;
                this.mText.textColor = this.mColor;
            }
            return;
        }// end function

        public function get selected() : Boolean
        {
            return this.mSelected;
        }// end function

        public function set label(param1:String) : void
        {
            this.mText.text = param1;
            this.mText.y = (this.mBtn.height - this.mText.height) / 2;
            return;
        }// end function

        public function set textFormat(param1:TextFormat) : void
        {
            this.mText.setTextFormat(param1);
            return;
        }// end function

        public function set glow(param1:Boolean) : void
        {
            if (param1)
            {
                if (!this.mFilter)
                {
                    this.mFilter = new DropShadowFilter(0, 0, 0, 0.8, 2, 2, 10, 1);
                }
                this.mText.filters = [this.mFilter];
            }
            else
            {
                this.mText.filters = [];
            }
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this.mData = param1;
            return;
        }// end function

        public function get data() : Object
        {
            return this.mData;
        }// end function

        public function set color(param1:uint) : void
        {
            if (this.mColor == param1)
            {
                return;
            }
            this.mColor = param1;
            if (!this.mSelected)
            {
                this.mText.textColor = param1;
            }
            return;
        }// end function

        public function get color() : uint
        {
            return this.mColor;
        }// end function

        public function set selectedColor(param1:uint) : void
        {
            if (this.mSelectedColor == param1)
            {
                return;
            }
            this.mSelectedColor = param1;
            if (this.mSelected)
            {
                this.mText.textColor = this.mSelectedColor;
            }
            return;
        }// end function

        public function get selectedColor() : uint
        {
            return this.mSelectedColor;
        }// end function

        override public function set width(param1:Number) : void
        {
            this.mBtn.width = param1;
            this.mText.width = param1;
            return;
        }// end function

        override public function set height(param1:Number) : void
        {
            this.mBtn.height = param1;
            this.mText.y = (param1 - this.mText.height) / 2;
            return;
        }// end function

        public function dispose() : void
        {
            if (this.mBtn)
            {
                if (this.mBtn.parent)
                {
                    this.mBtn.parent.removeChild(this.mBtn);
                }
                this.mBtn = null;
            }
            if (this.mText)
            {
                if (this.mText.parent)
                {
                    this.mText.parent.removeChild(this.mText);
                }
                this.mText = null;
            }
            return;
        }// end function

    }
}
